


import {$get,$post} from '@/utils/request'


import {$msg_e,$msg_s,$confirm} from '@/utils/msg'


export let list = async (params)=>{
    let ret = await $get('Student/List',params)
    console.log(ret)
    return ret
}


export let add = async (params) => {

    if(!checkInput(params)) return false

    let {success,message} = await $post('Student/Add',params)
    if(success){
        $msg_s(message)
    }else{
        $msg_e(message)
    }
    return success
}


export let update = async (params)=>{

    if(!checkInput(params)) return false

    let {success,message} = await $post('Student/Update',params)
    if(success){
        $msg_s(message)
    }else{
        $msg_e(message)
    }
    return success
}


let checkInput = (params)=>{
    if(!params.name){
        $msg_e('请输入学生姓名')
    }else if(!params.num){
        $msg_e('请输入学生学号')
    }else if(!params.class){
        $msg_e('请输入所在班级')
    }else{
        return true
    }
    return false
}



export let del =  async (params) => {

    await $confirm('是否确定删除')
    let {success,message} = await $post('Student/Delete',params)
    if(success){
        $msg_s(message)
    }else{
        $msg_e(message)
    }
    return success
}
